from datetime import datetime
from DB_MySQL import SqlHelper


def fetch_trade_day_before(some_day=datetime.today().date()):
    """
    获取指定日期当年的交易日期
    默认参数为当天
    :param some_day:
    :return:
    """
    return SqlHelper.get_instance().execute_query(
        "SELECT id,calendar,week FROM z_trade_calendar where is_trade_day = 0  and calendar<= curdate();")

    """ 获取到的结果使用：tuple类型需要使用序号获取：result[1]
        for result in results:
            today = datetime.today().date()
            if today == result[1]:
                print(result)
    """


if __name__ == '__main__':
    results = fetch_trade_day_before()
    for result in results:
        print(result[1])
